String clazzTpl({
  token,
  webHook,
  gitUrl,
  shellSymbol,
  branch,
  mergeTarget,
  androidMsg,
  iOSMsg,
  androidArgs,
  iOSArgs,
}) {
  String webhookStr = """WEB_HOOK = '$webHook'""";
  String noticeStr = '''
        stage('通知机器人?') {
            input {
                message "是否需要通知机器人?"
                ok "YES"
                parameters {
                    choice(name: 'IS_NOTICE', choices:['YES'])
                }
            }
            when {
                environment name: 'IS_NOTICE', value: 'YES'
            }
            steps {
                echo "\${IS_NOTICE}"
            }
        }
        stage('发送通知') {
            parallel {
                stage("android") {
                    stages {
                        stage("notice") {
                            steps {
                                sh "sleep 1"
                                script {
                                    notice(APP_QR_CODE_PATH_ANDROID, WEB_HOOK, MSG_ANDROID)
                                }
                            }
                        }
                    }
                }
                stage("iOS") {
                    stages {
                        stage("notice") {
                            steps {
                                sh "sleep 3"
                                script {
                                    notice(APP_QR_CODE_PATH_IOS, WEB_HOOK, MSG_IOS)
                                }
                            }
                        }
                    }
                }
            }
        }''';
  String noticeFuncStr = '''
@NonCPS
def notice(app_qr_code_path, web_hook, content) {
    sh """
    base64Str=\\\$(base64 -i \${app_qr_code_path})
    md5Str=\\\$(md5 \${app_qr_code_path} | cut -d\\'=\\' -f2 | awk \\'{sub(/^ */, "");sub(/ *\\\$/, "")}1\\')
    curl \${web_hook} \\\\
    -H "Content-Type: application/json" \\\\
    -d "{ \\\\
            \\\\"msgtype\\\\": \\\\"image\\\\", \\\\
            \\\\"image\\\\": { \\\\
                \\\\"base64\\\\": \\\\"\\\${base64Str}\\\\", \\\\
                \\\\"md5\\\\": \\\\"\\\${md5Str}\\\\" \\\\
            } \\\\
        }"
    curl \${web_hook} \\\\
    -H "Content-Type: application/json" \\\\
    -d "{ \\\\
            \\\\"msgtype\\\\": \\\\"text\\\\", \\\\
            \\\\"text\\\\": { \\\\
                \\\\"content\\\\": \\\\"\${content}\\\\", \\\\
                \\\\"mentioned_list\\\\": [\\\\"@all\\\\"] \\\\
            } \\\\
        }"
    """
}''';
  if (webHook == null || webHook.isEmpty) {
    noticeStr = "";
    noticeFuncStr = "";
    webhookStr = "";
  }
  String symbolStr = "";
  if (shellSymbol.isNotEmpty) {
    symbolStr = """
        stage('上传符号表') {
            steps {
                sh "echo 'upload symbol'"
                sh "$shellSymbol"
            }
        }""";
  }
  return '''
#!/usr/bin/env groovy

// 安装Jenkins推荐插件
// 可视化流水线需安装Blue Ocean插件[推荐安装]

pipeline {
    agent any

    environment { 
        TOKEN = '$token'
        $webhookStr
        GIT_URL = '$gitUrl'
        BRANCH = '$branch'
        MERGE_TARGET = '$mergeTarget'
        // android
        APP_PATH_ANDROID = "\${WORKSPACE}/build/app/outputs/flutter-apk/*.apk"
        APP_QR_CODE_PATH_ANDROID = "\${WORKSPACE}/build/app/outputs/flutter-apk/*.png"
        MSG_ANDROID = "$androidMsg"
        // iOS
        APP_PATH_IOS = "\${WORKSPACE}/build/ios/ipa/*.ipa"
        APP_QR_CODE_PATH_IOS = "\${WORKSPACE}/build/ios/ipa/*.png"
        MSG_IOS = "$iOSMsg"
    }

    options {
        timestamps()
        skipDefaultCheckout()
        timeout(time:60, unit:'MINUTES')
    }

    stages {
        stage('拉取代码') {
            steps {
                checkout([\$class: 'GitSCM', branches: [[name: "*/\${BRANCH}"]], extensions: [[\$class: 'PreBuildMerge', options: [mergeRemote: 'origin', mergeTarget: "\${MERGE_TARGET}"]]], userRemoteConfigs: [[url: "\${GIT_URL}"]]])
            }
        }
        stage('构建清理') {
            steps {
                sh """flutter clean && flutter pub get && flutter pub upgrade"""
            }
        }
        stage('构建') {
            parallel {
                stage("android") {
                    stages {
                        stage("build") {
                            steps {
                                sh """echo 'build'"""
                                sh """flutter build apk --release $androidArgs --build-number \\\${BUILD_NUMBER} --build-name \\\$(date +'%Y').\\\$(date +'%m').\\\$(date +'%d')"""
                            }
                        }
                    }
                }
                stage("iOS") {
                    stages {
                        stage("build") {
                            steps {
                                sh """echo 'build'"""
                                sh """flutter build ipa --release $iOSArgs --build-number \\\${BUILD_NUMBER} --build-name \\\$(date +'%Y').\\\$(date +'%m').\\\$(date +'%d')"""
                            }
                        }
                    }
                }
            }
        }
        stage('发布') {
            parallel {
                stage("android") {
                    stages {
                        stage("deploy") {
                            steps {
                                sh """echo 'deploy'"""
                                script {
                                    deploy(APP_PATH_ANDROID, TOKEN)
                                }
                            }
                        }
                    }
                }
                stage("iOS") {
                    stages {
                        stage("deploy") {
                            steps {
                                sh """echo 'deploy'"""
                                script {
                                    deploy(APP_PATH_IOS, TOKEN)
                                }
                            }
                        }
                    }
                }
            }
        }
$symbolStr
$noticeStr
        stage('完成') {
            steps {
                sh """echo '完成'"""
            }
        }
    }
}

@NonCPS
def deploy(app_path, token) {
    sh """
    fir p \${app_path} -c "\\\$(git log --pretty=format:"%ai %an: %s" --since="7 day ago")" -Q -T \${token}
    """
}

$noticeFuncStr
''';
}

// steps {
//     sh """echo 'build'"""
//     sh """flutter build ios --release"""
//     xcodeBuild appURL: '',
//     assetPackManifestURL: '',
//     buildDir: '',
//     buildIpa: true,
//     bundleID: '',
//     bundleIDInfoPlistPath: '',
//     cfBundleShortVersionStringValue: "\${JOB_BASE_NAME}.\${BUILD_NUMBER}",
//     cfBundleVersionValue: "\${BUILD_NUMBER}",
//     compileBitcode: false,
//     configuration: 'Release',
//     developmentTeamID: '',
//     developmentTeamName: '',
//     displayImageURL: '',
//     fullSizeImageURL: '',
//     ipaExportMethod: 'ad-hoc',
//     ipaName: 'Runner',
//     ipaOutputDirectory: "\${WORKSPACE}/build/app/outputs/flutter-ipa/",
//     logfileOutputDirectory: '',
//     manualSigning: false,
//     provideApplicationVersion: true,
//     provisioningProfiles: [[provisioningProfileAppId: '', provisioningProfileUUID: '']],
//     resultBundlePath: '',
//     sdk: '',
//     symRoot: '',
//     target: 'Runner',
//     thinning: '',
//     uploadBitcode: false,
//     xcodeProjectFile: "\${WORKSPACE}/ios/Runner",
//     xcodeProjectPath: "\${WORKSPACE}/ios/",
//     xcodeSchema: 'Runner',
//     xcodeWorkspaceFile: "\${WORKSPACE}/ios/Runner",
//     xcodebuildArguments: """
//     -allowProvisioningUpdates
//     -destination 'generic/platform=iOS'
//     "CODE_SIGN_RESOURCE_RULES_PATH=\\\$(SDKROOT)/ResourceRules.plist"
//     """
// }
